﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using L = Science.Mathematics.LinearAlgebra;

namespace Strang3Ed.Chapter02.Section6
{
    public class ExampleA
    {
        public ExampleA()
        {
        }
        private string result;
        public string Result
        {
            get { return result; }
        }
        public void Compute()
        {
            double[,] x = {{1.0,1.0,1.0,1.0},                           
                           {1.0,2.0,3.0,4.0},
                           {1.0,3.0,6.0,10.0},
                           {1.0,4.0,10.0,20.0}};

            L.Matrix A = new L.Matrix(x);

            L.FactorizationAeqCCt obj = new L.FactorizationAeqCCt(A);
            obj.Compute();

            L.Matrix C = obj.LowerTriangular;

            result += C.ToString();

            result += C.Transpose.ToString();

            L.Matrix P = C * C.Transpose;

            result += P.ToString();

            L.FactorizationPAeqLU obj2 = new L.FactorizationPAeqLU(A);
            obj2.Compute();

            L.Matrix U = obj2.UpperTriangular;

            result += U.ToString();
        }
    }
}
/*
1     0     0     0     
1     1     0     0     
1     2     1     0     
1     3     3     1     

1     1     1     1     
0     1     2     3     
0     0     1     3     
0     0     0     1     

1     1     1     1     
1     2     3     4     
1     3     6     10     
1     4     10     20     

1     1     1     1     // as explained in the book, something wrong
0     1     2     3     
0     0     3     10     
0     0     0     -0.333333333333333     
*/

